<div class="panel-body">
	<div class="table-responsive">
		<div class="dataTables_wrapper form-inline" id="dataTables-example_wrapper" role="grid">
			<div class="row" style="padding-bottom: 15px">
				<div class="col-sm-9">
					<div class="dataTables_length" id="dataTables-example_length">
						<select name="dataTables-example_length" class="form-control input-sm" aria-controls="dataTables-example" id="area" onchange="changearea()">
							<option value="">区/县</option>
						</select>
						<select name="dataTables-example_length" class="form-control input-sm" aria-controls="dataTables-example" id="work" onchange="changeTwon()">
							<option value="">分局</option>
						</select>
						<select name="dataTables-example_length" class="form-control input-sm" aria-controls="dataTables-example" id="wangge">
							<option value="">网格</option>
						</select>
						<select name="dataTables-example_length" class="form-control input-sm" aria-controls="dataTables-example" id="industryCategory">
							<option value="">行业</option>
							<option value="宾馆酒店">宾馆酒店</option>
							<option value="楼宇园区">楼宇园区</option>
							<option value="连锁集团">连锁集团</option>
							<option value="快递">快递</option>
							<option value="网吧">网吧</option>
						</select>
						<input name="dataTables-example_length" placeholder="商铺名称" class="form-control input-sm" aria-controls="dataTables-example" id="Name"/>
						<a class="btn btn-serch" onclick="Search()">查询</a>
						<a class="btn btn-serch" style="background: #3cbeb2;cursor:pointer !important;" data-options="iconCls:'icon-redo'" id="import">导入</a>
						<a class="btn btn-serch" style="background-color: #5a82f1;" onclick="ToExcel()">导出</a>
						<a class="btn btn-serch" style="background-color: #737eac;" onclick="ToTemplate()">模板下载</a>

					</div>
				</div>
				<div class="col-sm-3">
					<div class="dataTables_filter" id="dataTables-example_filter" style="float: right">
						<a class="btn btn-serch" onclick="AddShop()">新增</a>
					</div>
				</div>
			</div>
			<table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" aria-describedby="dataTables-example_info">
				<thead>
					<tr role="row">
						<th tabindex="0" class="sorting_asc" aria-controls="dataTables-example" style="text-align: center;width: 3%;" rowspan="1" colspan="1">序号
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 6%;" rowspan="1" colspan="1">店招
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 14%;" rowspan="1" colspan="1">名称
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 8%;" rowspan="1" colspan="1">行业<br>类别
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 5%;" rowspan="1" colspan="1">楼宇/酒<br>店类型
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 10%;" rowspan="1" colspan="1">店长<br>手机
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 5%;" rowspan="1" colspan="1">营销<br>状态
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 5%;" rowspan="1" colspan="1">网络<br>资源
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 5%;" rowspan="1" colspan="1">商客<br>经理
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 5%;" rowspan="1" colspan="1">区/县
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 7%;" rowspan="1" colspan="1">分局
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 11%;" rowspan="1" colspan="1">地址
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 8%;" rowspan="1" colspan="1">修改<br>时间
						</th>
						<th tabindex="0" class="sorting" aria-controls="dataTables-example" style="text-align: center;width: 8%;" rowspan="1" colspan="1">操作
						</th>
					</tr>
				</thead>
				<tbody id="shoplist">

				</tbody>
			</table>

		</div>

	</div>
</div>
<div class="row">
	<div id="page" style="float: right">

	</div>
</div>
<script>
	$(function() {

		$("#import").upload({
			action: GLOBAL.URL + "/dataload/upload?type=shop",
			name: 'file',
			autoSubmit: true,
			onComplete: function(data, self, element) {
				datas = JSON.parse(data);
				if(datas.code == 0) {
					AlertInfo("数据导入成功！");
				} else {
					AlertInfo("数据导入失败！");
				}
			}
		});
		var tableheight = 0;
		//加载数据
		getdata(1);
		GetArea();
	});

	//请求列表
	function getdata(page) {
		var json = {
			url: GLOBAL.URL + "/shopinfo/list",
			type: 'post',
			data: {
				"page": page,
				"limit": 15,
				"countryName": $("#area").val(),
				"branchOffice": $("#work").val(),
				"guidName": $("#wangge").val(),
				"industryCategory": $("#industryCategory").val(),
				"name":$("#Name").val(),
				"sidx":"modify_time",
				"order":"desc"
			},
			successfn: function(data) {
				UpdateShopList(data.page.list);
				setPage(data.page.totalPage);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}
	//加载商铺列表数据
	function UpdateShopList(data) {
		var listStr = "";
		if(data != null) {
			for(var i = 0; i < data.length; i++) {
				
				data[i].picPath = data[i].picPath == null ? "img/shop.png" : data[i].picPath;
				data[i].name = data[i].name == null ? "" : data[i].name;
				data[i].hotelCategory = data[i].hotelCategory == null ? "" : data[i].hotelCategory;
				data[i].scene = data[i].scene == null ? "" : data[i].scene;
				data[i].mangerName = data[i].mangerName == null ? "" : data[i].mangerName;
				data[i].countryName = data[i].countryName == null ? "" : data[i].countryName;
				data[i].branchOffice = data[i].branchOffice == null ? "" : data[i].branchOffice;
				data[i].town = data[i].town == null ? "" : data[i].town;
				data[i].village = data[i].village == null ? "" : data[i].village;
				data[i].villageNo = data[i].villageNo == null ? "" : data[i].villageNo;
				data[i].cell = data[i].cell == null ? "" : data[i].cell;
				data[i].shopKeeperPhone = data[i].shopKeeperPhone == null ? "未知" : data[i].shopKeeperPhone;
				data[i].marketingStatus = data[i].marketingStatus == null ? "" : data[i].marketingStatus;
				data[i].networkSource = data[i].networkSource == null ? "" : data[i].networkSource;
				data[i].industryCategory = data[i].industryCategory == null ? "" : data[i].industryCategory;
				data[i].modifyTime = data[i].modifyTime == null ? "" : data[i].modifyTime.substring(0,10);
				var name = data[i].name;
				if(name.length > 10) {
					name = name.substring(0, 10) + "...";
				}
				if(data[i].networkSource == null || data[i].networkSource == "") {
					data[i].networkSource = "";
				} else if(data[i].networkSource == "0") {
					data[i].networkSource = "否";
				} else {
					data[i].networkSource = "是";
				}
				if((i + 1) % 2 > 0) {
					listStr += '<tr class="gradeA odd">';
					listStr += '    <td style="text-align: center">' + (i + 1) + '</td>';
					listStr += '    <td style="text-align: center"><img src="' + data[i].picPath + '" onclick=bigImage("' + data[i].picPath + '") style="display: inline-block;cursor: pointer;" width="35" height="20" /></td>';
					listStr += '    <td style="text-align: left" title="' + data[i].name + '">' + name + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].industryCategory + '</td>';
					if(data[i].industryCategory == "宾馆酒店") {
						listStr += '    <td style="text-align: center">' + data[i].hotelCategory + '</td>';
					} else if(data[i].industryCategory == "楼宇园区") {
						listStr += '    <td style="text-align: center">' + data[i].scene + '</td>';
					} else {
						listStr += '    <td style="text-align: center"></td>';
					}
					listStr += '    <td style="text-align: center">' + data[i].shopKeeperPhone + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].marketingStatus + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].networkSource + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].mangerName + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].countryName + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].branchOffice + '</td>';
					listStr += '    <td>' + data[i].countryName + data[i].town + data[i].village + data[i].villageNo + data[i].cell + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].modifyTime + '</td>';
					listStr += '    <td style="text-align: center"><a onclick="EditShop(' + data[i].id + ')">编辑</a> <a onclick="DelShop(' + data[i].id + ')">删除</a></td>';
					listStr += '</tr>';
				} else {
					listStr += '<tr class="gradeA even">';
					listStr += '    <td style="text-align: center">' + (i + 1) + '</td>';
					listStr += '    <td style="text-align: center"><img src="' + data[i].picPath + '" onclick=bigImage("' + data[i].picPath + '") style="display: inline-block;cursor: pointer;" width="35" height="20" /></td>';
					listStr += '    <td style="text-align: left" title="' + data[i].name + '">' + name + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].industryCategory + '</td>';
					if(data[i].industryCategory == "宾馆酒店") {
						listStr += '    <td style="text-align: center">' + data[i].hotelCategory + '</td>';
					} else if(data[i].industryCategory == "楼宇园区") {
						listStr += '    <td style="text-align: center">' + data[i].scene + '</td>';
					} else {
						listStr += '    <td style="text-align: center"></td>';
					}
					listStr += '    <td style="text-align: center">' + data[i].shopKeeperPhone + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].marketingStatus + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].networkSource + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].mangerName + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].countryName + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].branchOffice + '</td>';
					listStr += '    <td>' + data[i].countryName + data[i].town + data[i].village + data[i].villageNo + data[i].cell + '</td>';
					listStr += '    <td style="text-align: center">' + data[i].modifyTime + '</td>';
					listStr += '    <td style="text-align: center"><a onclick="EditShop(' + data[i].id + ')">编辑</a> <a onclick="DelShop(' + data[i].id + ')">删除</a></td>';
					listStr += '</tr>';
				}
			}
		}
		$("#shoplist").html(listStr);
	}

	//查询
	function Search() {
		getdata(1);
	}
	$("#Name").keyup(function(){
		getdata(1);
	});
	
	//新增
	function AddShop() {
		GLOBAL.LOADURl = "Page/ShopManage/ShopList.html";
		$("#tabC").load("Page/shopmanage/shop/addshop.html");
		//SaveDialog("#AddShop", "Page/shopmanage/shop/addshop.html", "/shopinfo/save", "新增店铺");
	}

	//编辑商铺
	function EditShop(ID) {
		GLOBAL.LOADURl = "Page/ShopManage/ShopList.html";
		$("#tabC").load("Page/shopmanage/shop/editshop.html",function(){
			$.ajax({
				type: 'get', //请求的类型
				url: GLOBAL.URL + "/shopinfo/info/" + ID, //请求的地址
				dataType: "json", //返会值的类型
				async: false,
				xhrFields: {
					withCredentials: true
				},
				crossDomain: true,
				success: function(datas, textStatus) { //请求成功执行的代码
					if(datas.code == 0) {
						if(datas.info.countryName != null && datas.info.countryName != "") {
							GetWork(datas.info.countryName);
						}
						if(datas.info.countryName != null && datas.info.countryName != "" && datas.info.branchOffice != null && datas.info.branchOffice != "") {
							Getwangge(datas.info.countryName, datas.info.branchOffice);
						}
						if(datas.info.marketingStatus == "已拜访") {
							$("#packageFeeShow").hide();
							$("#expiryDateShow").hide();
							$("#reMarkShow").show();
						} else if(datas.info.marketingStatus == "已签约") {
							$("#packageFeeShow").show();
							$("#expiryDateShow").show();
							$("#reMarkShow").hide();
						} else {
							$("#packageFeeShow").hide();
							$("#expiryDateShow").hide();
							$("#reMarkShow").hide();
						}

						if(datas.info.industryCategory == "宾馆酒店") {
							$("#hotelCategoryShow").show();
							$("#hotelRoomCountShow").show();
							$("#hotelSignRoomCountShow").show();
							$("#sceneShow").hide();
							$("#buildingNameShow").hide();

						} else if(datas.info.industryCategory == "楼宇园区") {
							$("#hotelCategoryShow").hide();
							$("#hotelRoomCountShow").hide();
							$("#hotelSignRoomCountShow").hide();
							$("#sceneShow").show();
							$("#buildingNameShow").show();
						} else {
							$("#hotelCategoryShow").hide();
							$("#hotelRoomCountShow").hide();
							$("#hotelSignRoomCountShow").hide();
							$("#sceneShow").hide();
							$("#buildingNameShow").hide();
						}
					}
				}
			});
			loadForm("#EditShop", "/shopinfo/info/" + ID);
			$("#id").val(ID);
		});
		
//		SaveDialog("#EditShop", "Page/shopmanage/shop/editshop.html", "/shopinfo/update", "编辑店铺", function() {
//
//			$.ajax({
//				type: 'get', //请求的类型
//				url: GLOBAL.URL + "/shopinfo/info/" + ID, //请求的地址
//				dataType: "json", //返会值的类型
//				async: false,
//				xhrFields: {
//					withCredentials: true
//				},
//				crossDomain: true,
//				success: function(datas, textStatus) { //请求成功执行的代码
//					if(datas.code == 0) {
//						if(datas.info.countryName != null && datas.info.countryName != "") {
//							GetWork(datas.info.countryName);
//						}
//						if(datas.info.countryName != null && datas.info.countryName != "" && datas.info.branchOffice != null && datas.info.branchOffice != "") {
//							Getwangge(datas.info.countryName, datas.info.branchOffice);
//						}
//						if(datas.info.marketingStatus == "已拜访") {
//							$("#packageFeeShow").hide();
//							$("#expiryDateShow").hide();
//							$("#reMarkShow").show();
//						} else if(datas.info.marketingStatus == "已签约") {
//							$("#packageFeeShow").show();
//							$("#expiryDateShow").show();
//							$("#reMarkShow").hide();
//						} else {
//							$("#packageFeeShow").hide();
//							$("#expiryDateShow").hide();
//							$("#reMarkShow").hide();
//						}
//
//						if(datas.info.industryCategory == "宾馆酒店") {
//							$("#hotelCategoryShow").show();
//							$("#hotelRoomCountShow").show();
//							$("#hotelSignRoomCountShow").show();
//							$("#sceneShow").hide();
//							$("#buildingNameShow").hide();
//
//						} else if(datas.info.industryCategory == "楼宇园区") {
//							$("#hotelCategoryShow").hide();
//							$("#hotelRoomCountShow").hide();
//							$("#hotelSignRoomCountShow").hide();
//							$("#sceneShow").show();
//							$("#buildingNameShow").show();
//						} else {
//							$("#hotelCategoryShow").hide();
//							$("#hotelRoomCountShow").hide();
//							$("#hotelSignRoomCountShow").hide();
//							$("#sceneShow").hide();
//							$("#buildingNameShow").hide();
//						}
//					}
//				}
//			});
//			loadForm("#EditShop", "/shopinfo/info/" + ID);
//			$("#id").val(ID);
//		});
	}

	//删除
	function DelShop(ID) {
		AlertDel(deleteShop, ID);
	}

	var deleteShop = function(ID, dblChoseAlert) {
		$.ajax({
			type: 'get', //请求的类型
			url: GLOBAL.URL + "/shopinfo/delete?ids=" + ID, //请求的地址
			dataType: "json", //返会值的类型
			async: false,
			xhrFields: {
				withCredentials: true
			},
			crossDomain: true,
			success: function(datas, textStatus) { //请求成功执行的代码
				if(datas.code == 0) {
					var onlyChoseAlert = simpleAlert({
						"content": "删除成功！",
						"buttons": {
							"确定": function() {
								getdata(1);
								dblChoseAlert.close();
								onlyChoseAlert.close();
							}
						}
					});
				} else if(datas.code == "403") {
					AlertInfo("操作失败！" + datas.msg);
					window.location.href = "login.html";
				} else {
					var onlyChoseAlert = simpleAlert({
						"content": "请求失败！" + datas.msg,
						"buttons": {
							"确定": function() {
								dblChoseAlert.close();
								onlyChoseAlert.close();
							}
						}
					});
				}
			},
			error: function() {
				json.errorfn();
			}

		});
	}

	//获取区县
	function GetArea() {
		var json = {
			url: GLOBAL.URL + "/guidinfo/getAreaList",
			type: 'post',
			data: {
				"queryType": 0,
				"scope": 0
			},
			successfn: function(data) {
				SetArea(data.data);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}

	function SetArea(data) {
		var str = '<option value="">区/县</option>';
		for(var i = 0; i < data.length; i++) {
			str += '<option value="' + data[i].countryName + '">' + data[i].countryName + '</option>';
		}
		$("#area").html(str);
	}
	//区县点击
	function changearea() {
		if($("#area").val() == "") {
			$("#work").html('<option value="">分局</option>');
			$("#wangge").html('<option value="">网格</option>');
		} else {
			GetWork($("#area").val());
		}
	}
	//获取分局
	function GetWork(areastr) {
		var json = {
			url: GLOBAL.URL + "/guidinfo/getAreaList",
			type: 'post',
			data: {
				"area": areastr,
				"queryType": 1,
				"scope": 0
			},
			successfn: function(data) {
				SetWork(data.data);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}

	function SetWork(data) {
		var str = '<option value="">分局</option>';
		for(var i = 0; i < data.length; i++) {
			if(data[i] != null) {
				str += '<option value="' + data[i].branchOffice + '">' + data[i].branchOffice + '</option>';
			}
		}
		$("#work").html(str);
	}
	//分局点击
	function changeTwon() {
		if($("#area").val() == "" || $("#work").val() == "") {
			$("#wangge").html('<option value="">网格</option>');
		} else {
			Getwangge($("#area").val(), $("#work").val());
		}
	}
	//获取网格
	function Getwangge(areastr, workstr) {
		var json = {
			url: GLOBAL.URL + "/guidinfo/getAreaList",
			type: 'post',
			data: {
				"area": areastr,
				"town": workstr,
				"queryType": 2,
				"scope": 0

			},
			successfn: function(data) {
				SetWangge(data.data);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}

	function SetWangge(data) {
		var str = '<option value="">网格</option>';
		for(var i = 0; i < data.length; i++) {
			str += '<option value="' + data[i].gridName + '">' + data[i].gridName + '</option>';
		}
		$("#wangge").html(str);
	}

	//店招放大
	function bigImage(url) {
		ImageDialog(url);
	}
	//导出
	function ToExcel() {
		var countryName = $("#area").val();
		var branchOffice = $("#work").val();
		var guidName = $("#wangge").val();
		var industryCategory = $("#industryCategory").val();
		window.open(GLOBAL.URL + "/shopinfo/download?countryName=" + countryName + "&branchOffice=" + branchOffice + "&gridName=" + guidName + "&industryCategory=" + industryCategory);
	}

	//模板下载
	function ToTemplate() {
		window.open(GLOBAL.URL + "/template/shop_template.xlsx");
	}
</script>